<%--
  Created by IntelliJ IDEA.
  User: 20275
  Date: 2023/11/18
  Time: 16:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@include file="/pages/common/head.jsp"%>

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">修改密码</h1>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    修改密码
                </div>
                <div class="panel-body">
                    <div id="message_div" class="alert alert-danger"  role="alert" style="margin-top: 15px;display: none">两次密码不一致</div>
                    <form role="form" action="${pageContext.request.contextPath }/updatePwd" method="post" onsubmit="return validateForm()">

                        <div class="row">
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label>旧密码</label>
                                    <input class="form-control"  name="oldPwd" required >
                                </div>
                                <div class="form-group">
                                    <label>确认密码</label>
                                    <input class="form-control" onblur="handleBlur()" id="ok_pwd_input" name="ok_pwd" required>
                                </div>

                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label>新密码</label>
                                    <input class="form-control" onblur="handleBlur()" id="new_pwd_input" name="newPwd" required>
                                </div>
                                <input type="submit" class="btn btn-primary" value="修改">
                                <input type="reset" class="btn btn-warning" value="重置">
                            </div>
                        </div>

                    </form>

                </div>
            </div>
        </div>
    </div>
</div>

<c:if test="${message != null}">
    <script>
        alert("${message}")
    </script>

    <% session.removeAttribute("message");%>
</c:if>
<script>

    var pwd_ifOk = false
    function handleBlur(){
        var new_pwd_input = document.getElementById("new_pwd_input");
        var ok_pwd_input = document.getElementById("ok_pwd_input");
        var message_div = document.getElementById("message_div");

        if(new_pwd_input.value != "" && ok_pwd_input.value !=""){
            if(new_pwd_input.value != ok_pwd_input.value){
                pwd_ifOk = false
                message_div.style.display = "block";
            }else{
                pwd_ifOk = true
                message_div.style.display = "none";
            }
        }
    }
    function validateForm(){
        if (pwd_ifOk){
            return true
        }else{
            return false
        }
    }
</script>

<%@include file="/pages/common/foot.jsp" %>
